package game.core.util
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.geom.Point;
	import flash.utils.getQualifiedClassName;
	
	import game.core.IDispose;
	
	public class DisplayUtil
	{
		public function DisplayUtil()
		{
		}
		
		public static function removeAllChildren(container:DisplayObjectContainer,parent:DisplayObjectContainer = null):void {
			if(container){
				while(container.numChildren > 0){
					var child:DisplayObject = container.getChildAt(0);
					if(child is IDispose){
						IDispose(child).dispose();
					}
					container.removeChild(child);
				}
				removeChild(parent,container);
			}
		}
		
		public static function removeChild(parent:DisplayObjectContainer,child:DisplayObject):void {
			if(!parent)return;
			if(!child)return;
			if(parent.contains(child)){
				parent.removeChild(child);
			}
			child = null;
		}
		
		public static function getQualifiedClassName(value:Object):String {
			var name:String = flash.utils.getQualifiedClassName(value);
			var index:int = name.indexOf("::");
			if (index != -1){
				name = name.substr(index + 2);
			}
			return name;
		}
		
		public static function distance(t1:DisplayObject,t2:DisplayObject):Number {
			var p1:Point = new Point(t1.x,t1.y);
			var p2:Point = new Point(t2.x,t2.y);
			return Point.distance(p1,p2);
		}
	}
}